package edu.cmu.cs.stage3.alice.authoringtool.viewcontroller;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;

/**
 * @author Jason Pratt
 */
public class StylePropertyViewController extends PropertyViewController {
	protected javax.swing.JLabel styleLabel = new javax.swing.JLabel();
	protected Class valueClass;

	public void set( edu.cmu.cs.stage3.alice.core.Property property, boolean allowExpressions, boolean omitPropertyName, final edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory factory ) {
		super.set( property, true, true, true, omitPropertyName, factory );
		this.valueClass = property.getValueClass();
		if( ! edu.cmu.cs.stage3.alice.core.Style.class.isAssignableFrom( this.valueClass ) ) {
			throw new IllegalArgumentException( "valueClass of property " + property + " is not a Style; instead: " + valueClass );
		}
		setPopupEnabled( true );
		refreshGUI();
	}

	//Rem @Override
	protected java.awt.Component getNativeComponent() {
		return styleLabel;
	}

	//Rem @Override
	protected Class getNativeClass() {
		return edu.cmu.cs.stage3.alice.core.Style.class;
	}

	//Rem @Override
	protected void updateNativeComponent() {
		String text = AuthoringToolResources.getReprForValue( property.get(), property, property.getOwner().data );
		styleLabel.setText( text );
	}
}
